﻿@{
	Layout = "_LayoutImport";
	ViewBag.MaxFileSizeOfM = 10;
	ViewBag.Exts = ".xls,.xlsx";
	ViewBag.ImageThumbnails = "false";
}

@section header{
}

<table align="center" cellpadding="5" cellspacing="0" class="detail-panel-div" border="0">
	<tbody>
		<tr>
			<td colspan="2" height="50" valign="middle" align="left" class="detail-content-heading">@(ViewBag.Title)</td>
		</tr>
		<tr>
			<td colspan="2" align="left" valign="top" style="padding-left:40px;">
				<br>
				<span class="genHeaderGray">第一步:</span>&nbsp;
				<span class="genHeaderSmall">选择Excel文件</span>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="left" valign="top" style="padding-left:40px;">
				系统导入文件格式支持Excel 2003(.xls)、Excel 2007(.xlsx)，如果导入的文件有多个工作表（sheet），系统将只导入第一个工作表（sheet）。如果导入文件格式不支持，可以先下载样表，然后将数据复制到样表中之后再上传。
			</td>
		</tr>
		<tr><td align="left" valign="top" colspan="2">&nbsp;</td></tr>
		<tr>
			<td colspan="2" style="padding:0 40px;">
				<div class="dropzone needsclick dz-clickable" id="uploadDiv" style="border: 2px dashed #0087F7; border-radius: 5px; text-align: center;">
					<div class="fallback">
						<input name="file" type="file" multiple />
						<input type="submit" value="Upload" />
					</div>
					@*<input type="checkbox" name="has_header" checked="">&nbsp; 首行包含标题
						&nbsp;<input type="checkbox" name="overwrite">&nbsp; 覆盖重复记录*@
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2" style="text-align:center;height:60px;">
				<button class="pure-button pure-button-share" title="下载模板" onclick="window.location='@(Html.Raw(ViewBag.TplUrl))';return false;">
					<i class="icon-download"></i>
					下载模板
				</button>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<button class="pure-button pure-button-edit" title="上传" onclick="doUpload(); return false;">
					<i class="icon-upload"></i>
					上传
				</button>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<button class="pure-button pure-button-cancel" title="取消" onclick="closeUpload();return false;">
					<i class="icon-reply"></i> 取消
				</button>&nbsp;
			</td>
		</tr>
	</tbody>
</table>
@section footer{
	<script type="text/javascript">
		Dropzone.autoDiscover = false;
		var myDropzone = new Dropzone("#uploadDiv", {
			maxFiles: 1,
			dictMaxFilesExceeded: '最大上传文件数为1',
			parallelUploads:1,//同时上传最大文件数
			maxFilesize: @ViewBag.MaxFileSizeOfM,//M
			url: "@(Html.Raw(ViewBag.UploadUrl))",
			params:{ },
			addRemoveLinks: false,
			dictRemoveFile: '删除',
			dictCancelUpload: '取消上传',
			dictCancelUploadConfirmation: '文件正在上传中，取消上传可能会造成数据有误，确定取消吗？',
			createImageThumbnails: @ViewBag.ImageThumbnails,
			acceptedFiles: '@ViewBag.Exts',
			autoProcessQueue: false,
			dictDefaultMessage: '拖动要导入的Excel文件到此处或点击此处选择Excel文件上传',
			dictInvalidFileType: '不支持此类文件',
			init: function () {
				this.on("maxfilesexceeded", function (file) {
					//var files = this.getQueuedFiles();
					//myDropzone.removeFile(files[0]);
					myDropzone.removeFile(file);
					//myDropzone.addFile(file);
				});
				this.on("success", function (file, ret) {
					myDropzone.removeFile(file);
					if (ret.r) {
						if (window.opener && window.opener.@(ViewData["callback"])) {
							window.opener.@(ViewData["callback"])(ret.data);
						}
						if (window.parent && window.parent.@(ViewData["callback"])) {
							window.parent.@(ViewData["callback"])(ret.data);
						}
						closeUpload();
					} else {
						showAlert(ret.m);
					}
				});
				this.on("complete", function (file) {
					var resp = JSON.parse(file.xhr.response);
					if (!resp.r) {
						showAlert(resp.m,);
						myDropzone.removeFile(file);
					}
				});
				this.on('queuecomplete', function () {
					window.close();
				});

			}
		});

		function doUpload() {
			var files = myDropzone.getQueuedFiles();
			if (!files || files.length == 0) {
				showAlert("请选择要上传的文件");
				return;
			}
			myDropzone.processQueue();
		}

		function showAlert(msg) {
			parent.utils && parent.utils.alert && parent.utils.alert((msg||"").replace(/\n/g,"<br>"), null, {time: 8000});
		}

		function closeUpload() {
			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			parent.layer.close(index);
		}
	</script>
}